const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        show: false,
        code: '',
        name: '',
        expireTime: '',
        contractName: '',
        contractMobile: '',
        contractIdcard: '',
        truckSpaceName: '',
        truckSpace: {
            collectNum: '',
            consultNum: '',
            downPlaceNum: '',
            facePrice: '',
            projectName: '',
            level1Name: '',
            level2Name: '',
            level3Name: '',
            outsideArea: '',
            tagRespDtos: [],
            truckSpaceDetailImages: [],
        },
        downMoney: '',
        subMoney: '',
        xxhtk: '',
        // 确认核销信息弹窗
        info: {
            orderNo: '',
            truckSpaceCode: '',
            buyTypeName: '',
            money: '',
            buyMoney: '',
            contractName: '',
            contractIdcard: '',
            truckSpace: {
                sellPrice: ''
            },
            verify: ''
        },
        inputValue: '',
        inputValue1: '',
        inputValue2: '',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        wx.setNavigationBarTitle({
            title: '订单信息',
        });
        this.setData({
            code: options.code
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        wx.request({
          url: app.url + '/order/auth3/orderFormVerifyDetail/' + this.data.code ,
            method: 'get',
            header: {
                token: wx.getStorageSync('token')
            },
            //   data:{
            //       verifyCode: this.data.code
            //   },
            success: (res) => {
                if (res.data.code == 0) {
                    // console.log(res.data.data.realname)
                    this.setData({
                        expireTime: app.dateFormat(res.data.data.expireTime),
                        name: res.data.data.realname,
                        contractName: res.data.data.contractName,
                        contractMobile: res.data.data.contractMobile,
                        contractIdcard: res.data.data.contractIdcard,
                        sellPrice: res.data.data.truckSpace.sellPrice,
                        truckSpaceName: res.data.data.truckSpaceName,
                        truckSpace: res.data.data.truckSpace,
                        downMoney: res.data.data.downMoney,
                        subMoney: res.data.data.subMoney,
                        money: res.data.data.money,
                        buyMoney: res.data.data.buyMoney,
                        xxhtk: res.data.data.xxhtk,
                        verifyFund: res.data.data.verifyFund,
                        info: res.data.data,
                    })
                    wx.setStorageSync('contractName', res.data.data.contractName)
                    wx.setStorageSync('contractIdcard', res.data.data.contractIdcard)
                    wx.setStorageSync('sellPrice', res.data.data.truckSpace.sellPrice)
                } else {
                    wx.showModal({
                        title: '提示',
                        showCancel: false,
                        content: res.data.msg
                    });
                }
            }
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },

    // 顶部时间弹出
    showtimetop() {
        this.setData({
            showtimetop: !this.data.showtimetop
        })
    },
    //核销按钮
    cancel() {

        let contractName = wx.getStorageSync('contractName');
        let contractIdcard = wx.getStorageSync('contractIdcard');
        let sellPrice = wx.getStorageSync('sellPrice');
        this.setData({
            inputValue: contractName,
            inputValue1: contractIdcard,
            inputValue2: sellPrice,
        })
        this.setData({
            show: !this.data.show
        })

    },
    // 签约人输入框
    bindKeyInput(e) {
        // if (!e.detail.value) {
        //   wx.showModal({
        //     title: '提示',
        //     content: '请填写签约人',
        //   })
        //   return;
        // }
        this.setData({
            inputValue: e.detail.value
        })
    },
    // 身份证号码输入框
    bindKeyInput1(e) {
        console.log(e)
        // if (!e.detail.value) {
        //   wx.showModal({
        //     title: '提示',
        //     content: '请填写身份证号',
        //   })
        //   return;
        // }
        this.setData({
            inputValue1: e.detail.value
        })
    },
    // 最终成交价输入框
    bindKeyInput2(e) {
        console.log(e)
        // if(!e.detail.value){
        //   wx.showModal({
        //     title: '提示',
        //     content: '请填写最终成交价',
        //   })
        //   return ;
        // }
        this.setData({
            inputValue2: e.detail.value
        })
    },
    // 核销信息弹窗确定按钮
    sure() {
        if (this.data.inputValue == '') {
            wx.showModal({
                content: '请输入签约人',
            })
            return;
        }
        if (this.data.inputValue1 == '') {
            wx.showModal({
                content: '请输入身份证号码',
            })
            return;
        }
        if (this.data.inputValue2 == '') {
            wx.showModal({
                content: '请输入最终成交价',
            })
            return;
        }
        wx.request({
            url: app.url + '/order/auth3/orderFormVerify/verify',
            method: 'GET',
            header: {
                token: wx.getStorageSync('token')
            },
            data: {
                verifyCode: this.data.code,
                contractName: this.data.inputValue == '' ? this.data.info.contractName : this.data.inputValue,
                contractIdcard: this.data.inputValue1 == '' ? this.data.info.contractIdcard : this.data.inputValue1,
                money: this.data.inputValue2 == '' ? this.data.info.truckSpace.sellPrice : this.data.inputValue2
            },
            success: (res) => {
                if (res.data.code == 0) {
                    this.setData({
                        show: false,
                    })
                    this.onShow()
                } else {
                    wx.showModal({
                        title: '提示',
                        showCancel: false,
                        content: res.data.msg
                    });
                }
            }
        })
    },
    // 核销信息弹窗取消按钮
    deletes() {
        this.setData({
            show: false,
        })
    },
    // 核销成功返回首页
    goIndex(){
      wx.switchTab({
        url: '/pages/index/index',
      })
    }

})